#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  std::vector<int> v{5, 6, 4, 30, 2, 60, 7, 7, 7, 7, 7, 7, 7, 9, 3, 100, 1000};

  int nleft = (v.size() + 1) / 2;
  std::nth_element(v.begin(), v.begin() + nleft - 1, v.end());
  std::cout << "The median is " << v[v.size() / 2] << '\n';
  cout << "my median is " << v[nleft - 1] << endl;
  for (auto e : v)
    cout << e << " ";
  cout << endl;

  std::nth_element(v.begin(), v.begin() + 1, v.end(), std::greater<int>());
  std::cout << "The second largest element is " << v[1] << '\n';
}
